<template>
<!--面包屑-->
<div style="margin-bottom: 30px">
  <el-breadcrumb separator="/">
    <el-breadcrumb-item :to="{ path: '/Main' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>
      <router-link to="/Materials/ShowMaterialStatisticse">物资统计</router-link>
    </el-breadcrumb-item>
    <el-breadcrumb-item>物资统计列表</el-breadcrumb-item>
  </el-breadcrumb>
</div>

  <!--查询条件-->
  <div style="margin-bottom: 30px;">
    货物名称：<el-input v-model="form.nameOfGoods" placeholder="请输入货物名称" style="width: 240px;"></el-input>&nbsp;&nbsp;
    材质：<el-input v-model="form.material" placeholder="请输入材质" style="width: 240px;"></el-input>&nbsp;&nbsp;
    产地：<el-select v-model="form.CountryId" placeholder="请选择国家" size="large" style="width: 240px" @change="getEconomizeList">
      <el-option v-for="item in countryData" :key="item.countryId" :label="item.countryName" :value="item.countryId"/>
    </el-select>
        
        &nbsp;&nbsp;
        <el-select v-model="form.EconomizeId" placeholder="请选择省/州" size="large" style="width: 240px">
      <el-option v-for="item in EconomizeData" :key="item.economizeId" :label="item.economizeName" :value="item.economizeId"/>
    </el-select>
    <br/>
    <br/>
    统计区间：<el-date-picker v-model="form.startDate" type="date" placeholder="请选择开始日期" format="YYYY/MM/DD" value-format="YYYY-MM-DD"/>&nbsp;&nbsp;
    至
    <el-date-picker v-model="form.endDate" type="date" placeholder="请选择截止日期" format="YYYY/MM/DD" value-format="YYYY-MM-DD"/>
    &nbsp;&nbsp;
    <el-button type="primary" @click="getMaterialsList">查询</el-button>
    <el-button @click="reset">重置</el-button>
  </div>
  
  <!--物资列表-->
  <div>
    <el-table :data="MaterialsData" border style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" />
      <el-table-column prop="nameOfGoods" label="货物名称" align="center" />
      <el-table-column prop="materialStoreType" label="类型" align="center" width="90px" />
      <el-table-column prop="material" label="材质" align="center" />
      <el-table-column prop="specifications" label="规格" align="center" />
      <el-table-column label="产地" align="center" width="230px" >
      <template v-slot="scope">
        {{ scope.row.countryName }} -- {{scope.row.economizeName}}
      </template>
    </el-table-column>
      <el-table-column prop="totalNumber" label="期间采购数量" align="center" />
      <el-table-column prop="quantityReceived" label="期间领用数量" align="center" />
      <el-table-column prop="number" label="期末结余数量" align="center" />
    </el-table>
  </div>
  
  <!--分页-->
  <div>
    <table>
    <thead></thead>
    <tbody>
      <tr>
        <td>
          <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[15, 20, 25, 30]" :background="true" layout="total,slot, sizes" :total="form.totalCount" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
            <span>
              ，每页{{ form.pageSize }}条，当前第:{{ form.pageIndex }}/{{ form.pageCount }}页
            </span>
          </el-pagination>
        </td>
  
        <td>
          <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[15, 20, 25, 30]" :background="true" layout="slot, prev, pager, next" :total="form.totalCount" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
            <el-button type="primary" class="btn-prev" @click="handleCurrentChange(1)" :disabled="form.pageIndex==1">首页</el-button>
          </el-pagination>
        </td>
  
        <td>
          <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[15, 20, 25, 30]" :background="true" layout="slot, jumper" :total="form.totalCount" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
            <el-button type="primary" class="btn-prev" @click="handleCurrentChange(form.pageCount)" :disabled="form.pageIndex==form.pageCount">尾页</el-button>
          </el-pagination>
        </td>
      </tr>
    </tbody>
  </table>
  </div>
  </template>
  
  <script setup lang="ts">
  import { reactive, ref, onMounted, computed } from 'vue'
  import axios from 'axios';
  import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
  import { ElMessage, ElMessageBox } from 'element-plus'
  
  import {useRoute,useRouter} from 'vue-router'
  
  const route = useRoute();
  const router = useRouter();
  const dialogFormVisible:any = ref(false)
  const formLabelWidth = '140px'
  const formSize = ref<ComponentSize>('default')
  
  onMounted(() => {
    //物资列表
    getMaterialsList()

    getCountryList()
    getEconomizeList()
  })
  
  const form: any = reactive({
    nameOfGoods: '',
    material: '',
    CountryId: '',
    EconomizeId: '',
    applicant: '',
    approvalStatus: '',
    paymentMethod: '',
    startDate: '',
    endDate:'',
    pageIndex: 1,
    pageSize: 15,
    pageCount: 0,
    totalCount: 0,
  })
  
//存储多选中的物资id
const multipleSelection:any = ref([]);
const handleSelectionChange = (val:any) => {
  // console.log(val);
  multipleSelection.value = val;
  // console.log(multipleSelection.value); 
}

  //获取国家列表
  const countryData: any = ref([]);
  const getCountryList = () => {
    axios.get('/mread/api/ShowMaterialStore/GetCountryList', {
      params: {
        
      }
    }).then(res=>{
    //console.log(res);
      countryData.value = res.data.data;
  }).catch(err=>{
    console.log(err);
    
  })    
  }

    //获取省/州列表
    const EconomizeData: any = ref([]);
  const getEconomizeList = () => {
     form.EconomizeId = "";
    axios.get('/mread/api/ShowMaterialStore/GetEconomizeList', {
      params: {
        CountryId: form.CountryId || 0
      }
    }).then(res=>{
    //console.log(res);
    
    EconomizeData.value = res.data.data;
  }).catch(err=>{
    console.log(err);
    
  })    
  }
  
  //分页
  const handleSizeChange = (val: number) => {
    form.pageSize = val;
    getMaterialsList()
  }
  const handleCurrentChange = (val: number) => {
    form.pageIndex = val;
    getMaterialsList()
  }
  
  //物资列表
  const MaterialsData: any = ref([])
  const getMaterialsList = () => {
  
    axios.get('/mread/api/ShowMaterialStatistics/GetMaterialStatisticsList', {
      params: {
        NameOfGoods: form.nameOfGoods,
        Material: form.material,
        CountryId: form.CountryId,
        EconomizeId: form.EconomizeId,
        startDate: form.startDate,
        endDate: form.endDate,
        pageIndex: form.pageIndex,
        pageSize: form.pageSize,
      }
    }).then(res=>{
      console.log(res);
      MaterialsData.value = res.data.data.list;
      
      form.totalPage = res.data.data.pageCount;
      form.totalCount = res.data.data.totalCount;
    }).catch(err=>{
      console.log(err);
      
    })    
  }
  
  //重置
  const reset = () => {
    form.nameOfGoods = '',
      form.material = '',
      form.CountryId = '',
      form.EconomizeId = '',
      form.applicant = '',
      form.approvalStatus = '',
      form.paymentMethod = '',
      form.startDate = '',
      form.endDate = '',
      form.pageIndex = 1,
      form.pageSize = 15,
      getMaterialsList()
  }
  
  </script>
  
  <style scoped>
  
  </style>